package legoproject;

import java.awt.GridLayout;
import legoproject.Behaviors.Behavior;
import javax.swing.*;
import java.awt.Color;

public class PCReporter implements StatusReporter {

    private JFrame frame;
    private JPanel container;
    private JTextArea textArea = null;

    public PCReporter(String name){
        frame = new JFrame("Nxt unit: " + name);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        container = new JPanel(new GridLayout(3,10), true);
        frame.getContentPane().add(container);
        frame.pack();
        frame.setVisible(true);
        

    }

    public void addComponent(JComponent component){
        component.setBorder(BorderFactory.createLineBorder(Color.black));
        container.add(component);
        frame.pack();
    }


    public void behaviorChange(Behavior newBehavior, Behavior oldBehavior) {
        if(textArea == null){
            textArea = new JTextArea("Current Behavior:\n", 2, 33);
            textArea.setOpaque(true);
            addComponent(textArea);
        }
        else{
            textArea.setText("current bahvior:\n" + newBehavior);
        }
    }

    public void executingInstruction(int type, int arg1, int arg2) {
        if (type == InstructionType.DRIVE) {
            System.out.println("instr- Driving " + arg1 + "with balance" + arg2);
        } else if (type == InstructionType.ROTATE) {
            System.out.println("instr- Rotating " + arg1);
        } else {
            System.out.println("executin instruction type " + type + "with" + "(" + arg1 + "," + arg2 + ")");
        }
    }

    public void sendingBTCommand(int command) {
        System.out.println("sendingBTCommand: " + command);
    }

    public void error(int error) {
        System.out.println("ERROR: " + error);
    }

    public void ready() {
    }

    public void executingCommand(int type){
        if (type == CommandType.GRAB) {
            System.out.println("cmd- GRAB ");
        } else if (type == CommandType.RELEASEGRAB) {
            System.out.println("cmd- RELEASEGRAB ");
        } else {
            System.out.println("executin command type " + type);
        }
    }

    public void nameStat(int number, String name){}

    public void updateStat(int number, int value){}

    public void updateLCD(){}

}

